import axios from 'axios'
import { changeInputAction2,changeInputAction3,changeInputAction1,changeInputAction, addItemAction, getListAction, postItemAction,putItemAction, deleteItemAction } from '../store/actionCreators'
var getTime = () => {
    var date = new Date();

    var year = date.getFullYear().toString();
    var month = (date.getMonth() + 1).toString();
    var day = date.getDate().toString();
    var hour = date.getHours().toString();
    var minute = date.getMinutes().toString();
    if (minute < 10) minute = '0' + minute;
    return year + '/' + month + '/' + day + ' ' + hour + ':' + minute;
}
export default dispatchToProps = (dispatch) => {
    return {
        inputChange(value) {
            let action = changeInputAction(value)
            dispatch(action)
        },
        inputChange1(value) {
            let action = changeInputAction1(value)
            dispatch(action)
        },
        inputChange2(value) {
            let action = changeInputAction2(value)
            dispatch(action)
        },
        inputChange3(value) {
            console.log(value)
            let action = changeInputAction3(value)
            dispatch(action)
        },
        clickBtn() {
            let time=getTime()
            let action = addItemAction(time)
            dispatch(action)
        },
        getFun(url) {
            axios.get(url).then((res) => {
                const data = res.data
                let action = getListAction(data)
                dispatch(action)
            })
        },
        postFun(obj, url) {
            let data = {
                //使用方法
                // id:obj.id
            }
            axios.post(url, data).then((res) => {
                let action = postItemAction(data)
                dispatch(action)
            })
        },
        deleteFun(obj, url) {
            let data = {
                //使用
                // id:obj.id
            }
            axios.delete(url, data).then((res) => {
                let action = deleteItemAction(data)
                dispatch(action)
            })
        },
        putFun(obj, url) {
            let data = {
                //使用
                // id:obj.id
            }
            axios.delete(url, data).then((res) => {
                let action = putItemAction(data)
                dispatch(action)
            })
        },

    }
}